﻿using System;
using System.Threading;

namespace DarcRogue
{
    class Program
    {
        static Player player;
        static Map map;
        static MainMenu mainMenu;
        static Hud hud;
        static bool exit = false;

        static void Main(string[] args)
        {
            Setup(args);
            while (Loop()) ;
        }

        static void Setup(string[] args)
        {
            Console.CursorVisible = false;
            Console.Title = "DarcRogue";
            mainMenu = new MainMenu();
            mainMenu.AddNewItem("New Game", ButtonFunction.NewGame);
            mainMenu.AddNewItem("Load Game", ButtonFunction.LoadGame);
            mainMenu.AddNewItem("Options", ButtonFunction.Options);
            mainMenu.AddNewItem("Help", ButtonFunction.Help);
            mainMenu.AddNewItem("Credits", ButtonFunction.Credits);
            mainMenu.AddNewItem("Exit", ButtonFunction.Exit);
            FileManager.Setup();
            Map.Setup();
        }
        static bool Loop()
        {
            if (exit)
                return false;
            if (mainMenu != null)
                mainMenu.Update();
            if (mainMenu != null)
                mainMenu.Draw();
            if (player != null && player.Update())
                map.Update();
            if (player != null)
            {
                Console.Clear();
                map.Draw();
                player.Draw();
                hud.Draw();
            }
            Thread.Sleep(1000 / 30);
            return true;
        }

        public static void Help()
        {
            Console.Clear();
            //Do Help
        }
        public static void LoadGame()
        {
            Console.Clear();
            //Do LoadGame
        }
        public static void NewGame()
        {
            Console.Clear();
            mainMenu = null;
            map = Map.Random(new Player(null, 2, 2));
            map.Player.Map = map;
            player = map.Player;
            hud = new Hud(map);
            map.Hud = hud;
        }
        public static void Credits()
        {
            Console.Clear();
            //Do Credits
        }
        public static void Exit()
        {
            exit = true;
        }
        public static void Options()
        {
            Console.Clear();
            //Do Options
        }
    }
}
